package is.server.controller.session.remote.command;

import is.common.datatype.Request;
import is.common.exception.RowNotFoundException;
import is.common.interfaces.Command;
import is.common.util.ObjectStreamer;
import is.server.Main;

import java.io.IOException;

/**
 * @author aspr0
 *         Date: 01.05.12
 *         Time: 3:53
 */
public class FindCommand implements Command
{
    private ObjectStreamer objectStreamer;
    private int sectionNum;
    private String[] masks;

    public FindCommand(Request request, ObjectStreamer objectStreamer)
    {
        sectionNum = request.getSectionNum();
        masks = request.getData();
        this.objectStreamer = objectStreamer;

    }

    @Override
    public void execute()
    {
        try
        {
            String[][] rows = Main.getController().getModel().findRows(sectionNum, masks);
            objectStreamer.transmitObject(rows);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (RowNotFoundException e)
        {
            e.printStackTrace();
        }

    }
}
